package sudoku.main;

import java.util.ArrayList;
import java.util.Collections;

public class Square {

	private int sudokuSize;
	private int number = -1;
	private ArrayList<Integer> chance;
	private boolean sure = false;
	private int x;
	private int y;


	public Square(int sudokuSize, int x, int y) {
		this.sudokuSize = sudokuSize;
		chance = new ArrayList<Integer>(sudokuSize);
		for(int i = 1; i <= sudokuSize; i++) {
			chance.add(i);
		}
		this.x = x;
		this.y = y;
	}


	public void setSure(int number) {
		sure = true;
		this.number = number;
		this.chance.clear();
	}

	public void clear() {
		sure = false;
		number = -1;
		for(int i = 1; i <= sudokuSize; i++) {
			chance.add(i);
		}
	}

	public void clearChances() {
		chance.clear();
		for(int i = 1; i <= sudokuSize; i++) {
			chance.add(i);
		}
	}

	public void addChance(int number) {
		chance.add(number);
		Collections.sort(chance);
	}

	public void removeChance(Integer number) {
		chance.remove(number);
	}

	public int getNumber() {
		if(this.sure) {
			return this.number;
		}
		else
			return -1;
	}
	
	public boolean isSure() {
		return sure;
	}
	
	public int howManyPossibilities() {
		return chance.size();
	}
	
	public ArrayList<Integer> getPossibilities() {
		return chance;
	}






	public String toString() {
		if(sure) {
			return ""+number;
		}
		else {
			String possibilities = "";
			for(int i = 1; i <= sudokuSize; i++) {
				if(chance.contains(i)) {
					possibilities = possibilities+" "+i;
				}
				else {
					possibilities = possibilities+"  ";
				}
				if(i == 3 || i == 6) {
					possibilities = possibilities+"\n";
				}
			}
			return possibilities;
		}
	}

}
